#include"House.h"

House :: House(){

}

House ::House(const List<Room> &_AllRooms, const Door &_HeadDoor, const List<Window> &_OutWindows){
	AllRooms = _AllRooms;
	HeadDoor = _HeadDoor;
	OutWindows = _OutWindows;
}

void House :: HouseSimulation(){
	for(int i=0; i<AllRooms.GetSize(); i++){
		Room ExistRoom;
		AllRooms.Retrieve(i, ExistRoom);
		ExistRoom.RoomSimulation();
	}
	HeadDoor.DoorSimulation();
	for(int j=0; j<OutWindows.GetSize(); j++){
		Window ExistWindow;
		OutWindows.Retrieve(j, ExistWindow);
		ExistWindow.WindowSimulation();
	}
}

void House :: AddRoom(Room &R){
	Room ExistRoom;
	for(int i=0; i<AllRooms.GetSize(); i++){
		AllRooms.Retrieve(i, ExistRoom);
		if(R ==  ExistRoom) break;
	}
	if(R !=ExistRoom) AllRooms.Insert(AllRooms.GetSize(), R);
	else cout<<"R is duplicate in the house!"<<endl;
}

void House :: AddWindow(Window &W){
	Window ExistWindow;
	for(int i=0; i<OutWindows.GetSize(); i++){
		OutWindows.Retrieve(i, ExistWindow);
		if(W ==  ExistWindow) break;
	}
	if(W !=ExistWindow) OutWindows.Insert(OutWindows.GetSize(), W);
	else cout<<"W is duplicate in the house!"<<endl;
}

List<Msg> House :: MsgofHouse(){
	List<Msg> AllInformation;
	List<Msg> tempInformation;
	for(int i=0; i<AllRooms.GetSize(); i++){
		Room ExistRoom;
		AllRooms.Retrieve(i, ExistRoom);
		tempInformation = ExistRoom.GetMsg();
		for(int j=0; j<tempInformation.GetSize(); j++){
			Msg temp;
			tempInformation.Retrieve(j, temp);
			AllInformation.Insert(AllInformation.GetSize(), temp);
		}
	}
	tempInformation = HeadDoor.GetMsg();
	for(int k=0; k<tempInformation.GetSize(); k++){
			Msg temp;
			tempInformation.Retrieve(k, temp);
			AllInformation.Insert(AllInformation.GetSize(), temp);
	}
	for(int m=0; m<OutWindows.GetSize(); m++){
		Window ExistWindow;
		OutWindows.Retrieve(m, ExistWindow);
		tempInformation = ExistWindow.GetMsg();
		for(int n=0; n<tempInformation.GetSize(); n++){
			Msg temp;
			tempInformation.Retrieve(n, temp);
			AllInformation.Insert(AllInformation.GetSize(), temp);
		}
	}
	return AllInformation;
}
